#include "Popup/Popup_customService.h"
#include "Util/ImageManager.h"
#include "Util/SoundManager.h"

bool Popup_customService::init()
{
	if (!CCLayerColor::initWithColor(ccc4(0,0,0,0)))
	{
		return false;
	}

	winSize = CCDirector::sharedDirector()->getWinSize();

	mainLayer = CCLayer::create();
	mainLayer->setPosition(ccp(-winSize.width,0));
	this->addChild(mainLayer);

	bg = CCSprite::create("custom_service_bg.png");
	bg->setAnchorPoint(ccp(0,0));
	mainLayer->addChild(bg);

	btn_close = ImageManager::getSpriteWithXml2(kImageSheet_freemium,"button_close");
	btn_close->setPosition(ccp(300,400));
	mainLayer->addChild(btn_close);

	return true;
}

void Popup_customService::openPopup()
{
	mainLayer->setPosition(ccp(-winSize.width, 0));
	CCMoveTo *move = CCMoveTo::create(0.2, ccp(0,0));
	CCEaseExponentialOut* accel = CCEaseExponentialOut::create(move);
	mainLayer->runAction(accel);

	CCFadeTo* fade = CCFadeTo::create(0.2, 200);
	this->runAction(fade);
	SoundManager::PlaySoundEffect(sndEffect_zoomin);
}

void Popup_customService::closePopup()
{
	CCMoveTo *move = CCMoveTo::create(0.2, ccp(-winSize.width,0));
	CCEaseExponentialIn* accel = CCEaseExponentialIn::create(move);
	mainLayer->runAction(accel);

	CCFadeTo* fade = CCFadeTo::create(0.2, 0);
	CCCallFunc *cf = CCCallFunc::create(this,callfunc_selector(Popup_customService::removeFromParent));
	this->runAction(CCSequence::create(fade,cf,NULL));
	SoundManager::PlaySoundEffect(sndEffect_zoomout);
}


int Popup_customService::touchEnded(CCPoint pt)
{
	if (btn_close->boundingBox().containsPoint(pt))
	{
		return customService_btn_close;
	}
	return -1;
}